/*所属税局*/
$(function(){
	var flag = false;
    var setting = {
		check: {  
			enable: true,  
			nocheckInherit: false  
		},
		view: {showIcon: false},
		async: {
			enable: true,
			url:'../ztree/script/demo.json',
			autoParam:['id', 'level=lv'],
            dataFilter:function(treeId, parentNode, childNodes){
                if(!childNodes) return null;
                for (var i=0, l=childNodes.length; i<l; i++) {
                    childNodes[i].name = childNodes[i].text;
                    childNodes[i].isParent = childNodes[i].state == 'open' ? false : true;
                }
                return childNodes;
			},
		},
        callback:{
            onExpand:function(){
                layerResize('ztree');
            },
            onCollapse:function(){
            	layerResize('ztree');
            },
            onDblClick:function(event, treeId, treeNode){
            	$('#countryTax').val(treeNode.name);
            	$('#nationTax').val(treeNode.id);
            	layerHide('ztree');
            },
            onAsyncSuccess:function(e, treeId){
            	layerResize('ztree');
            }
        }
	};
    $('#countryTax').click(function(){
    	var that = $(this), ztree = $('<div class="ztree" id="ztree"></div>').appendTo('body');
    	$.fn.zTree.init($("#ztree"), setting);
    	$.layer({
    		content:ztree,
    		isFadein:false,
    		theme:'ztree',
    		height:'auto',
    		title:{
    			text:'请选择国税'
    		},
    		confirm:{
    			enable:true,
    			callback:function(){
					var ztree = $.fn.zTree.getZTreeObj('ztree').getSelectedNodes()[0];
    				if(ztree !== undefined){
    					that.val(ztree.name);
    					$('#nationTax').val(ztree.id);
    				}
    				return true;
    			}
    		},
    		isMove:false
    	});
    });
});